/*
** StockDB
**
** Copyright (C) 2012 - ? doublegsoft
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROTOCOL_H__
#define __PROTOCOL_H__

#define PROTOCOL_HEADER    "~!@#$%^&*"
#define PROTOCOL_FOOTER    "*&^%$#@!~"

/*!
** order is
**
**
*/
typedef struct protocol_t
{
  unsigned int order;
  unsigned int len;
  char *data;
} protocol_t;

/*!
**
**
*/
typedef enum order_e
{
  INSERT = 1,
  SELECT = 2
} order_e;

/*!
** Checks the given data is whether have stockdb protocol header.
**
** @param[in] data
**              raw data from client
**
** @param[in] size
**              length of the raw data
**
** @return true return zero; false return
**         less-than-zero.
*/
int
stockdb_protocol_header(const char *data, size_t size);

/*!
** Checks the given data is whether have stockdb protocol footer.
**
** @param[in] data
**              raw data from client
**
** @param[in] size
**              length of the raw data
**
** @return true return the end index of protocol delimiter; false return
**         less-than-zero.
*/
int
stockdb_protocol_footer(const char *data, size_t size);

/*!
** Gets the data from the request raw data.
**
** @param[in] data
**              raw data from client
**
** @param[in] size
**              the end delimiter index
**
** @return data
*/
const char *
stockdb_protocol_data(const char *data, int end);

#endif


